package com.nageoffer.jobtrain.admin.controller;

import com.nageoffer.jobtrain.admin.dto.req.AdminUserLoginReqDTO;
import com.nageoffer.jobtrain.admin.dto.req.AdminUserRegisterReqDTO;
import com.nageoffer.jobtrain.admin.dto.resp.AdminUserLoginRespDTO;
import com.nageoffer.jobtrain.admin.service.AdminUserService;
import com.nageoffer.jobtrain.common.web.result.Result;
import com.nageoffer.jobtrain.common.web.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员用户接口控制层 -ToB业务
 * author：唐晨
 */
@RestController
@RequiredArgsConstructor
public class AdminUserController {
    private final AdminUserService adminUserService;

    /**
     * 管理员用户注册功能
     */
    @PostMapping("/api/job-train/admin/user/register")
    public Result<Void> registerAdminUser(@RequestBody AdminUserRegisterReqDTO requestParam) {
        adminUserService.registerAdminUser(requestParam);
        return Results.success();
    }

    /**
     * 管理员用户登录功能
     */
    @PostMapping("/api/job-train/admin/user/login")
    public Result<AdminUserLoginRespDTO> loginAdminUser(@RequestBody AdminUserLoginReqDTO requestParam) {
        AdminUserLoginRespDTO result = adminUserService.loginAdminUser(requestParam);
        return Results.success(result);
    }

    /**
     * 获取到当前登录的用户名
     */
    @PostMapping("/api/job-train/admin/user/get-username")
    public Result<String> getAdminUserName() {
        return adminUserService.getAdminUserName();
    }

    /**
     * 管理员用户退出登录
     */
    @PostMapping("/api/job-train/admin/user/logout")
    public Result<Boolean> logoutAdminUser() {
        return Results.success(adminUserService.logoutAdminUser());
    }
}
